<?php
$print = false;
$ok = false;
$path = '../_api/';
$files = array();

require('./check.php');
if ((bool) $ok) {
	// if there is a connection download files
	$data = file_get_contents('http://www.xprogress.com/_projects/bbclone-api/api/getFiles.php');
	$data = json_decode($data);
	if (!is_dir($path)) mkdir($path);
	foreach ($data as $f=>$d) {
		if ($handle = fopen($path.$f, 'w')) {
			if(!fwrite($handle, $d)) $ok = false;
			else $files[] = $f;
			fclose($handle);
		}
		else $ok = false;
	}
}
$res = array();
$res['result'] = 1;
$res['files'] = $files;
echo json_encode($res);
?>